# Contributor: August Klein <amatcoder@gmail.com>
# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=nzbget
pkgver=24.3
pkgrel=0
pkgdesc="Usenet downloader"
url="https://nzbget.com"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	libxml2-dev
	openssl-dev
	boost-dev
	cmake
	samurai
	"
depends="7zip"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="https://github.com/nzbgetcom/nzbget/archive/v$pkgver/nzbget-$pkgver.tar.gz
	nzbget.conf
	nzbget.initd
	nzbget.confd
	0002-install-to-webapps.patch"

case "$CARCH" in
	# tests fails: lscpu: not found
	aarch64|ppc64le|riscv64|s390x|loongarch64) options="!check";;
esac

prepare() {
	default_prepare

	# remove default curses
	# disable update check
	sed -e "s|^OutputMode=.*|OutputMode=color|" \
		-e "s|^UpdateCheck=.*|UpdateCheck=none|" \
		-i nzbget.conf
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DENABLE_TESTS=ON \
		-DDISABLE_CURSES=ON
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install

	# template config
	install -Dm644 build/nzbget.conf -t "$pkgdir"/usr/share/nzbget/
	# user config
	install -Dm644 "$srcdir"/nzbget.conf -t "$pkgdir"/var/lib/nzbget/

	install -Dm755 "$srcdir"/nzbget.initd "$pkgdir"/etc/init.d/nzbget
	install -Dm644 "$srcdir"/nzbget.confd "$pkgdir"/etc/conf.d/nzbget
}

sha512sums="
6a79f7fcc58c494af19179b6a98d5235423fc8d3a45c6ba969cf687948da25faaf9bcec074b7c9b8ccf2d3621e6bc2dc9c2ae67e877e89fa9a00b8f3ff4ca85a  nzbget-24.3.tar.gz
8b3dbd8d76a23f8534ce933ff056d236e6bd83cac724faa555f1b4adaa5e36f93446884973c0874c1ee51ecf931fe7b9573a3c594cb562b77548575bb8c65ad2  nzbget.conf
20ce714d380c69a8335176ca90e29f803594e6f51d328bc702180a898d1d8ad050fdf84b4c7db3217e15abf87faeb24081327f3b167ff2706cbafeb07fd75db5  nzbget.initd
1eb1203295381aa9960fc1472d2272580af1973f87e5156392bc4dcf5544d7b0984ace7aeddff196dab875cff485dfdf599ecd9b8a36b3f2de6db53a0beb8163  nzbget.confd
10c84a496de3cf273e48ebf8afe07ba51f6edbef6c039249164159d4683ba550daca63ecc50ccc3f2dae21e86cd2c9d97943fd0a997561f51af1ca775dc133d6  0002-install-to-webapps.patch
"
